from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `answer` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `question` VARCHAR(255)   COMMENT '问题',
    `answer` LONGTEXT   COMMENT '回答',
    `add_id` INT   COMMENT '录入人' DEFAULT 0,
    KEY `idx_answer_created_01c6d4` (`created_at`),
    KEY `idx_answer_updated_77f83e` (`updated_at`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_api` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `path` VARCHAR(100) NOT NULL  COMMENT 'API路径',
    `method` VARCHAR(6) NOT NULL  COMMENT '请求方法',
    `summary` VARCHAR(500) NOT NULL  COMMENT '请求简介',
    `tags` VARCHAR(100) NOT NULL  COMMENT 'API标签',
    KEY `idx_admin_api_created_619b3f` (`created_at`),
    KEY `idx_admin_api_updated_bfa461` (`updated_at`),
    KEY `idx_admin_api_path_6d2a06` (`path`),
    KEY `idx_admin_api_method_e8ce2b` (`method`),
    KEY `idx_admin_api_summary_ff7e21` (`summary`),
    KEY `idx_admin_api_tags_da7ee8` (`tags`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_auditlog` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `user_id` INT NOT NULL  COMMENT '用户ID',
    `username` VARCHAR(64) NOT NULL  COMMENT '用户名称' DEFAULT '',
    `module` VARCHAR(64) NOT NULL  COMMENT '功能模块' DEFAULT '',
    `summary` VARCHAR(128) NOT NULL  COMMENT '请求描述' DEFAULT '',
    `method` VARCHAR(10) NOT NULL  COMMENT '请求方法' DEFAULT '',
    `path` VARCHAR(255) NOT NULL  COMMENT '请求路径' DEFAULT '',
    `status` INT NOT NULL  COMMENT '状态码' DEFAULT -1,
    `response_time` INT NOT NULL  COMMENT '响应时间(单位ms)' DEFAULT 0,
    `datas` JSON   COMMENT '提交数据',
    KEY `idx_admin_audit_created_a8e9d5` (`created_at`),
    KEY `idx_admin_audit_updated_f02ec6` (`updated_at`),
    KEY `idx_admin_audit_user_id_76f7a2` (`user_id`),
    KEY `idx_admin_audit_usernam_75fb48` (`username`),
    KEY `idx_admin_audit_module_20c766` (`module`),
    KEY `idx_admin_audit_summary_283973` (`summary`),
    KEY `idx_admin_audit_method_4cdc16` (`method`),
    KEY `idx_admin_audit_path_0b6d7f` (`path`),
    KEY `idx_admin_audit_status_bbab09` (`status`),
    KEY `idx_admin_audit_respons_1303a0` (`response_time`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `Customers` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `qymc` VARCHAR(255)   COMMENT '企业名称',
    `qysh` VARCHAR(255)   COMMENT '企业税号',
    `zjqk` VARCHAR(255)   COMMENT '资金缺口',
    `kp24` VARCHAR(255)   COMMENT '2024年开票',
    `kp23` VARCHAR(255)   COMMENT '2023年开票',
    `name` VARCHAR(255)   COMMENT '法人姓名',
    `sfz` VARCHAR(255)   COMMENT '身份证号码',
    `phone` VARCHAR(255)   COMMENT '手机号码',
    `address` VARCHAR(255)   COMMENT '企业地址',
    `yh_no` VARCHAR(255)   COMMENT '银行卡号',
    `yh_khh` VARCHAR(255)   COMMENT '开户行',
    `yh_phone` VARCHAR(255)   COMMENT '预留手机号',
    `hyzk` VARCHAR(255)   COMMENT '婚姻状况',
    `po_name` VARCHAR(255)   COMMENT '配偶姓名',
    `po_phone` VARCHAR(255)   COMMENT '配偶手机号',
    `po_sfz` VARCHAR(255)   COMMENT '配偶身份证号',
    `contact1` VARCHAR(255)   COMMENT '紧急联系人1',
    `contact2` VARCHAR(255)   COMMENT '紧急联系人2',
    `sfz_z` VARCHAR(255)   COMMENT '法人身份证正面',
    `sfz_f` VARCHAR(255)   COMMENT '法人身份证反面',
    `yyzz` VARCHAR(255)   COMMENT '营业执照副本',
    `price` VARCHAR(255)   COMMENT '金额',
    `add_uid` INT   COMMENT '归属经理' DEFAULT 0,
    `status` INT   COMMENT '状态' DEFAULT 0,
    KEY `idx_Customers_created_a97e10` (`created_at`),
    KEY `idx_Customers_updated_22d0ea` (`updated_at`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `Customers_follow` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `qymc` VARCHAR(255)   COMMENT '企业名称',
    `qysh` VARCHAR(255)   COMMENT '企业税号',
    `name` VARCHAR(255)   COMMENT '法人姓名',
    `yh_no` VARCHAR(255)   COMMENT '银行卡号',
    `yh_khh` VARCHAR(255)   COMMENT '开户行',
    `yh_phone` VARCHAR(255)   COMMENT '预留手机号',
    KEY `idx_Customers_f_created_85bae6` (`created_at`),
    KEY `idx_Customers_f_updated_6a1fc0` (`updated_at`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_dept` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `name` VARCHAR(20) NOT NULL UNIQUE COMMENT '部门名称',
    `desc` VARCHAR(500)   COMMENT '备注',
    `is_deleted` BOOL NOT NULL  COMMENT '软删除标记' DEFAULT 0,
    `order` INT NOT NULL  COMMENT '排序' DEFAULT 0,
    `parent_id` INT NOT NULL  COMMENT '父部门ID' DEFAULT 0,
    KEY `idx_admin_dept_created_3431cb` (`created_at`),
    KEY `idx_admin_dept_updated_18af7a` (`updated_at`),
    KEY `idx_admin_dept_name_2e143c` (`name`),
    KEY `idx_admin_dept_is_dele_4b618a` (`is_deleted`),
    KEY `idx_admin_dept_order_045892` (`order`),
    KEY `idx_admin_dept_parent__a3942f` (`parent_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_dept_closure` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `ancestor` INT NOT NULL  COMMENT '父代',
    `descendant` INT NOT NULL  COMMENT '子代',
    `level` INT NOT NULL  COMMENT '深度' DEFAULT 0,
    KEY `idx_admin_dept__created_4f1a78` (`created_at`),
    KEY `idx_admin_dept__updated_851f06` (`updated_at`),
    KEY `idx_admin_dept__ancesto_5dc444` (`ancestor`),
    KEY `idx_admin_dept__descend_5fc68b` (`descendant`),
    KEY `idx_admin_dept__level_25c2a6` (`level`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_downloads` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `name` VARCHAR(255) NOT NULL  COMMENT '文件名称',
    `state` INT NOT NULL  COMMENT '下载状态' DEFAULT 0,
    `type` INT NOT NULL  COMMENT '1发票2excel' DEFAULT 1,
    `user_id` INT NOT NULL  COMMENT '生成人ID' DEFAULT 0,
    `url` VARCHAR(255) NOT NULL  COMMENT '下载路径',
    `count` INT NOT NULL  COMMENT '下载次数' DEFAULT 0,
    `fapiao_count` INT NOT NULL  COMMENT '文件数量' DEFAULT 1,
    KEY `idx_admin_downl_created_53f56d` (`created_at`),
    KEY `idx_admin_downl_updated_5675bd` (`updated_at`),
    KEY `idx_admin_downl_user_id_d5b9fe` (`user_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `jobs_log` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `user_id` INT NOT NULL  COMMENT '关联人id' DEFAULT 0,
    `job_id` INT NOT NULL  COMMENT '任务id' DEFAULT 0,
    `result_status` INT   COMMENT '执行结果1成功2失败' DEFAULT 0,
    `result_data` LONGTEXT   COMMENT '执行返回数据',
    KEY `idx_jobs_log_created_8a28b6` (`created_at`),
    KEY `idx_jobs_log_updated_18664d` (`updated_at`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `jobs_rule` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `type` INT NOT NULL  COMMENT '任务类型' DEFAULT 1,
    `name` VARCHAR(255) NOT NULL  COMMENT '任务标题',
    `func_name` VARCHAR(255) NOT NULL  COMMENT '访问url',
    `times` INT   COMMENT '执行间隔(秒)' DEFAULT 0,
    `day` INT   COMMENT '天' DEFAULT 0,
    `hour` INT   COMMENT '时' DEFAULT 0,
    `minute` INT   COMMENT '分' DEFAULT 0,
    `second` INT   COMMENT '秒' DEFAULT 0,
    `state` BOOL NOT NULL  COMMENT '执行状态' DEFAULT 0,
    `up_type` INT   COMMENT '启动方式1自启动2手动启动' DEFAULT 1,
    KEY `idx_jobs_rule_created_7934c8` (`created_at`),
    KEY `idx_jobs_rule_updated_db7ced` (`updated_at`),
    KEY `idx_jobs_rule_type_fcec96` (`type`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_menu` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `name` VARCHAR(20) NOT NULL  COMMENT '菜单名称',
    `remark` JSON   COMMENT '保留字段',
    `menu_type` VARCHAR(7)   COMMENT '菜单类型',
    `icon` VARCHAR(100)   COMMENT '菜单图标',
    `path` VARCHAR(100) NOT NULL  COMMENT '菜单路径',
    `order` INT NOT NULL  COMMENT '排序' DEFAULT 0,
    `parent_id` INT NOT NULL  COMMENT '父菜单ID' DEFAULT 0,
    `is_hidden` BOOL NOT NULL  COMMENT '是否隐藏' DEFAULT 0,
    `component` VARCHAR(100) NOT NULL  COMMENT '组件',
    `keepalive` BOOL NOT NULL  COMMENT '存活' DEFAULT 1,
    `redirect` VARCHAR(100)   COMMENT '重定向',
    KEY `idx_admin_menu_created_95f056` (`created_at`),
    KEY `idx_admin_menu_updated_41a534` (`updated_at`),
    KEY `idx_admin_menu_name_38edba` (`name`),
    KEY `idx_admin_menu_path_136a39` (`path`),
    KEY `idx_admin_menu_order_1db47a` (`order`),
    KEY `idx_admin_menu_parent__2227d9` (`parent_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_notices` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `title` VARCHAR(255) NOT NULL  COMMENT '名称',
    `type` INT NOT NULL  COMMENT '通知类型' DEFAULT 0,
    `user_id` INT NOT NULL  COMMENT '通知人ID' DEFAULT 0,
    `status` INT NOT NULL  COMMENT '状态0未处理1已处理' DEFAULT 0,
    `go_path` VARCHAR(255) NOT NULL  COMMENT '跳转路由',
    KEY `idx_admin_notic_created_61fa8d` (`created_at`),
    KEY `idx_admin_notic_updated_afa1d5` (`updated_at`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_role` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `name` VARCHAR(20) NOT NULL UNIQUE COMMENT '角色名称',
    `desc` VARCHAR(500)   COMMENT '角色描述',
    KEY `idx_admin_role_created_6ab434` (`created_at`),
    KEY `idx_admin_role_updated_89e0f6` (`updated_at`),
    KEY `idx_admin_role_name_4e4d9a` (`name`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_user` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `created_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6),
    `updated_at` DATETIME(6) NOT NULL  DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
    `deleted_at` DATETIME(6),
    `username` VARCHAR(20) NOT NULL UNIQUE COMMENT '用户名称',
    `alias` VARCHAR(30)   COMMENT '姓名',
    `email` VARCHAR(255) NOT NULL UNIQUE COMMENT '邮箱',
    `phone` VARCHAR(20)   COMMENT '电话',
    `password` VARCHAR(128)   COMMENT '密码',
    `is_active` BOOL NOT NULL  COMMENT '是否激活' DEFAULT 1,
    `is_superuser` BOOL NOT NULL  COMMENT '是否为超级管理员' DEFAULT 0,
    `last_login` DATETIME(6)   COMMENT '最后登录时间',
    `dept_id` INT   COMMENT '部门ID',
    `avatar` VARCHAR(255)   COMMENT '头像',
    KEY `idx_admin_user_created_8b5146` (`created_at`),
    KEY `idx_admin_user_updated_fca352` (`updated_at`),
    KEY `idx_admin_user_usernam_46688a` (`username`),
    KEY `idx_admin_user_alias_71bbf2` (`alias`),
    KEY `idx_admin_user_email_5c5886` (`email`),
    KEY `idx_admin_user_phone_e01cb2` (`phone`),
    KEY `idx_admin_user_is_acti_c1acc4` (`is_active`),
    KEY `idx_admin_user_is_supe_a37fe8` (`is_superuser`),
    KEY `idx_admin_user_last_lo_f35531` (`last_login`),
    KEY `idx_admin_user_dept_id_182871` (`dept_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_role_admin_menu` (
    `admin_role_id` BIGINT NOT NULL,
    `menu_id` BIGINT NOT NULL,
    FOREIGN KEY (`admin_role_id`) REFERENCES `admin_role` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`menu_id`) REFERENCES `admin_menu` (`id`) ON DELETE CASCADE,
    UNIQUE KEY `uidx_admin_role__admin_r_0ecb44` (`admin_role_id`, `menu_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_role_admin_api` (
    `admin_role_id` BIGINT NOT NULL,
    `api_id` BIGINT NOT NULL,
    FOREIGN KEY (`admin_role_id`) REFERENCES `admin_role` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`api_id`) REFERENCES `admin_api` (`id`) ON DELETE CASCADE,
    UNIQUE KEY `uidx_admin_role__admin_r_be4986` (`admin_role_id`, `api_id`)
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `admin_user_admin_role` (
    `admin_user_id` BIGINT NOT NULL,
    `role_id` BIGINT NOT NULL,
    FOREIGN KEY (`admin_user_id`) REFERENCES `admin_user` (`id`) ON DELETE CASCADE,
    FOREIGN KEY (`role_id`) REFERENCES `admin_role` (`id`) ON DELETE CASCADE,
    UNIQUE KEY `uidx_admin_user__admin_u_de5a13` (`admin_user_id`, `role_id`)
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
